﻿<common:LayoutAwarePage
    x:Class="Looptribe.Moodlin8.View.UserMessagesPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:h2xaml="using:Html2Xaml"
    xmlns:common="using:Looptribe.Moodlin8.Common" xmlns:looptribe="using:Looptribe.WinRT.Toolkit"
    DataContext="{Binding UserMessages, Source={StaticResource Locator}}"
    mc:Ignorable="d">
    
    <Page.Resources>
        <Style x:Key="SectionStyle" TargetType="Grid">
            <Setter Property="Margin" Value="40,0,40,0"/>
        </Style>

        <DataTemplate x:Key="MessagesTemplate">
            <Grid Margin="0,0,0,2">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="70" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Width="70" Height="70" VerticalAlignment="Top">
                    <Image Source="{Binding Sender.Image}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Sender.FirstName}"/>
                </Border>

                <StackPanel Orientation="Vertical" Grid.Column="1">
                    <TextBlock Text="{Binding Sender.Title}" Style="{StaticResource TitleTextStyle}" TextWrapping="NoWrap" Margin="10,0,10,0"/>

                    <TextBlock Text="{Binding Subject}" Style="{StaticResource CaptionTextStyle}" Margin="10,10,10,0" TextWrapping="WrapWholeWords" />
                    <TextBlock Text="{Binding Body}" Style="{StaticResource BodyTextStyle}" Margin="10" TextWrapping="WrapWholeWords" />
                </StackPanel>
            </Grid>
        </DataTemplate>
    </Page.Resources>

    <Page.BottomAppBar>
        <AppBar x:Name="BottomAppBar1" Padding="10,0,10,0" AutomationProperties.Name="Bottom App Bar" Background="{StaticResource MoodleOrangeColor}" Foreground="White">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <StackPanel x:Name="RightPanel" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right">
                    <Button x:Name="Refresh" Style="{StaticResource MoodleRefreshAppButtonStyle}" Tag="Refresh" Command="{Binding RefreshCommand}"/>
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.BottomAppBar>

    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <ProgressBar IsIndeterminate="True" Grid.Row="1" Visibility="{Binding IsLoading,Converter={StaticResource BooleanToVisibilityConverter}}" />

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <StackPanel Orientation="Horizontal" Grid.Column="1">
                <TextBlock x:Name="pageTitle" Text="{Binding User.Fullname}" Style="{StaticResource MoodleAppTitleSyle}"/>
                <Image Source="ms-appx:///Assets/Nav_arrow.png" Margin="0,60,0,0" Stretch="None" VerticalAlignment="Center"></Image>
            </StackPanel>
        </Grid>

        <Grid Grid.Row="1" Margin="90,0,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="360" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid Style="{StaticResource SectionStyle}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="360"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <Image Source="{Binding User.ProfileImageUrl}" Stretch="UniformToFill" />
            </Grid>
            
            <ScrollViewer Grid.Column="1">
                <ListView ItemsSource="{Binding Messages}" ItemTemplate="{StaticResource MessagesTemplate}" SelectionMode="None" IsSwipeEnabled="False" />
            </ScrollViewer>
            
            <Grid Grid.Column="1" Grid.Row="1" Margin="0,5,0,5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBox x:Name="messageTextBox" Margin="0,0,5,0" TextWrapping="Wrap" />
                <Button Padding="30,10" Background="{StaticResource MoodleOrangeColor}" Foreground="White"
                        Content="Send" Grid.Column="1" Click="SendClick" />
            </Grid>
        </Grid>
        <!--Overview-->

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>